﻿Imports System.Data.OleDb

Partial Public Class AddImages
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_UploadImage_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_UploadImage.Click
        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("PlacesConnectionString").ToString())

        Dim addImageSQL As String = "INSERT INTO UserUploadedImages(Picture, PictureName, UserName) VALUES(@Picture, @PictureName, @UserName)"

        Dim fileLocationOnServer = Request.MapPath("Images/UserUploadedImages/" & upload_Image.FileName)

        upload_Image.SaveAs(fileLocationOnServer)

        Dim relativePath As String = "Images/UserUploadedImages/" & upload_Image.FileName


        Dim dbcmd = New OleDbCommand(addImageSQL, conn)

        dbcmd.Parameters.AddWithValue("@Picture", relativePath)
        dbcmd.Parameters.AddWithValue("@PictureName", tb_ImageName.Text)
        dbcmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        conn.Open()
        dbcmd.ExecuteNonQuery()
        Response.Redirect("MyImages.aspx?ID=" & User.Identity.Name)
    End Sub
End Class